package com.lyncs.ods.resp;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.lyncs.ods.constant.LyncsOdsConstant;
import com.lyncs.ods.modules.company.model.CompanyContactInfo;
import com.lyncs.ods.modules.company.model.CompanyInfo;
import com.lyncs.ods.modules.company.model.ContactInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author alex
 * @date 2022/2/2 14:38
 * @description
 */
@Data
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class CompanyDetailInfoResp {

    @ApiModelProperty("企业ID")
    private Long companyId;

    @ApiModelProperty(value = "全称")
    private String name;

    @ApiModelProperty(value = "简称")
    private String shortName;

    @ApiModelProperty(value = "所属行业ID")
    private Long industry;

    @ApiModelProperty(value = "员工规模")
    private String scale;

    @ApiModelProperty(value = "头像")
    private String avatarUrl;

    @ApiModelProperty(value = "地址")
    private String address;

    @ApiModelProperty("电话号码")
    private String telephone;

    @ApiModelProperty("传真号码")
    private String fax;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty("企业标语")
    private String slogan;

    @ApiModelProperty("企业背景图URL")
    private String backgroundImg;

    @ApiModelProperty("订单交易数量")
    private CountInfo orderInfo;

    @ApiModelProperty("交付单数量")
    private CountInfo deliverInfo;

    @ApiModelProperty("结算单数量")
    private CountInfo settlementInfo;

    @ApiModelProperty(value = "是否注册。true:是;false:否")
    private Boolean register;

    @ApiModelProperty("国家ID")
    private Long countryId;

    @ApiModelProperty("国家")
    private String countryName;

    @ApiModelProperty("货币（取关联国家的默认货币）")
    private String currency;

    @ApiModelProperty("关系类型:1.供应商;2.客户;多个用英文逗号拼接")
    private String type;

    @ApiModelProperty("初始B类企业ID")
    private Long initCompanyId;

    @ApiModelProperty(value = "能否编辑")
    private Boolean canEdit;

    @ApiModelProperty(value = "权限组信息")
    private List<CompanyGroupInfo> companyGroupInfos;

    public CompanyDetailInfoResp() {
    }

    public CompanyDetailInfoResp(CompanyInfo companyInfo) {
        this.companyId = companyInfo.getId();
        this.name = companyInfo.getName();
        this.shortName = companyInfo.getShortName();
        this.industry = companyInfo.getIndustry();
        this.scale = companyInfo.getScale();
        this.avatarUrl = companyInfo.getAvatarUrl();
        this.slogan = companyInfo.getSlogan();
        this.backgroundImg = companyInfo.getBackgroundImg();
        this.countryId = companyInfo.getCountry();
        this.register = LyncsOdsConstant.CompanyStatus.ENABLE.getKey().equals(companyInfo.getStatus());
        this.setCanEdit(Boolean.FALSE);
    }

    public CompanyDetailInfoResp(CompanyInfo companyInfo, CompanyContactInfo companyContactInfo) {
        ContactInfo contactInfo = companyContactInfo.getContactDetail();
        //以下字段用企业中的属性填充
        this.companyId = companyInfo.getId();
        this.name = companyInfo.getName();
        //this.shortName = companyInfo.getShortName();这个字段暂时为nickname
        this.initCompanyId = companyContactInfo.getInitCompanyId();
        this.avatarUrl = companyInfo.getAvatarUrl();
        this.slogan = companyInfo.getSlogan();
        this.backgroundImg = companyInfo.getBackgroundImg();
        this.register = LyncsOdsConstant.CompanyStatus.ENABLE.getKey().equals(companyInfo.getStatus());
        //以下字段为备注信息
        this.shortName = companyContactInfo.getNickname();
        this.address = contactInfo.getAddress();
        this.email = contactInfo.getEmail();
        this.fax = contactInfo.getFax();
        this.telephone = contactInfo.getTelephone();
        this.countryId = contactInfo.getCountry();
        this.setCanEdit(Boolean.TRUE);
    }


    @Data
    @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
    @AllArgsConstructor
    public static class CountInfo {

        @ApiModelProperty("当前登录用户作为卖方发出的单据")
        private Integer asSeller;

        @ApiModelProperty("当前登录用户作为买方收到的单据")
        private Integer asBuyer;
    }
}
